package Control;

/**
 *
 * @author Juan Ortiz
 */
public class DESForecasting implements IForecasting {

    private double alfa = 0.3;   // where alfa is the data smoothing factor 0 < alfa < 1
    private double beta = 0.48;   //beta is the trend smoothing factor 0 < beta < 1
    private double S1; //formula of the algorithms see some lines down
    private double b1; //formula of the algorithms see some lines down
    private double St; //formula of the algorithms see some lines down
    private double bt; //formula of the algorithms see some lines down


    @Override
    public Double[] forecast(Double[] inputs) throws IllegalArgumentException {
        
        if(!Validator.validate(inputs))
            throw new IllegalArgumentException("The inputs' number must be equal or greater than 5.");
            
        
        Double[] outputs = new Double[inputs.length ];

        S1 = inputs[0];
        b1 = inputs[1] - inputs[0];
        outputs[0] = inputs[0];

        for (int i = 1; i < inputs.length; i++) {

            St = (alfa * inputs[i]) + (1 - alfa) * (S1 + b1);
            bt = beta * (St - S1) + (1 - beta) * b1;

            outputs[i] = this.St + this.bt;

            S1 = St;
            b1 = bt;
        }
        return outputs;
    }
}
